//
//  NSString+Extand.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/22.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "NSString+Extand.h"

@implementation NSString (Extand)

- (NSString *)retureTimeStringWithFormate:(NSString *)timeFormate{
    return [self retureTimeStringWithFormate:timeFormate multiple:1];
}

- (NSString *)retureTimeStringWithFormate:(NSString *)timeFormate multiple:(NSInteger)multiple{
    NSTimeInterval interval = [self doubleValue];
    interval = interval / multiple;    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
    [objDateformat setDateFormat:timeFormate];
    NSString * timeStr = [NSString stringWithFormat:@"%@",[objDateformat stringFromDate:date]];
    return timeStr;
}

- (NSString *)returnTimeStringMin{
    NSTimeInterval interval = [self doubleValue];
    interval = interval / 1000;
    NSInteger min = interval / 60;
    return [NSString stringWithFormat:@"%@分钟",@(min)];
}
/**
 *  手机号码验证
 *
 *  @param mobileNumbel 传入的手机号码
 *
 *  @return 格式正确返回true  错误 返回fals
 */
+ (BOOL) isMobile:(NSString *)mobileNumbel{
    /**
     * 手机号码
     * 移动：134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188
     * 联通：130 131 132 145 155 156 171 175 176 185 186
     * 电信：133 149 153 173 177 180 181 189
     * 虚拟运营商: 170
     */
    NSString *target = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[0135678]|18[0-9]|14[579])[0-9]{8}$";
    NSPredicate *targetPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", target];
    if ([targetPredicate evaluateWithObject:mobileNumbel]) {
        return YES;
    }
    
    return NO;
}
/**
 *  邮箱地址验证
 *
 *  @param emailAddress 传入的邮箱地址
 *
 *  @return 格式正确返回true  错误 返回fals
 */
+ (BOOL )isEmailAddress:(NSString *)emailAddress{
    //匹配正则
    NSString *target = @"^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$";
    
    NSPredicate *targetPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", target];
    
    if ([targetPredicate evaluateWithObject:emailAddress]) {
        return YES;
    }
    
    return NO;
}

@end
